home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / XCMD libraries 960603 / xcmdWind.h < prev   
C/C++ Source or Header  |  1996-01-31  |  5KB  |  131 lines

  1. #pragma    once
  2. #include    "xcmdBase.h"
  3. #include    "xcmdStrings.h"
  4.  
  5. //    © Paul B. Beeken, Work In Progress, 1994-5
  6. //    Knowledge Software Consulting.
  7. //
  8. //    These files are a mindlessly simple wrapper class for the
  9. //    basic XCMD operations.  Only one instance of the xcmdBase class is
  10. //    generated per XCMD call but there may be many instances of the XCMDString
  11. //    class.  I have used these classes to whip out XCMD/XFCNs within hours of
  12. //    receiving the specs.  They work great for me but I will always consider 
  13. //    suggestions.
  14. //
  15. //    Please, please, please, in the unlikely event you should use this stuff
  16. //    for some commercial application I would appreciate you contacting me.  If
  17. //    its for your own use, use away. Send email: knowsoft@ios.com
  18. //
  19. //    As always: this file is presented as is with no warrantees expressed or implied.
  20. //    Swim at your own risk, etc. etc.
  21.  
  22. //
  23. //    This is the base class for all Xwindow objects.
  24. //        It is a decendant of the xcmdBase because, while there doesn't seem
  25. //        to be any specific prohibition to multiple windows per xcmd, it is a
  26. //        practical limitation.  HC only maintains one windowPtr per xcmd call.
  27. //        Thus when I handle operations I can only deal with one window at a time.
  28. //        N.B. there can be multiple windows through multiple calls for the xcmd
  29. //        to open windows.  The result of this is that the xcmd event called is for
  30. //        the front most window.  The xcmd must either limit the windows or not assume
  31. //        anything about the state of the window when the event call is made.
  32. //
  33. //    The idea is to override most of the default actions listed below.
  34.  
  35. class    xcmdWindow : public xcmdBase    {
  36.  
  37.     public:
  38.     
  39.         xcmdWindow( XCmdPtr xP, Boolean lockParams=false );
  40.         ~xcmdWindow();
  41.         
  42.             // Test for establishing if we entered as a result of a toolbox "event."
  43.         Boolean        isWindowEvent( void )            { return xEventInfo != nil; }
  44.  
  45.             // This is the entry point for handling events.
  46.         void        doWindowEvent( void );
  47.  
  48.             // These tools to help create windows and set properties.
  49.         CWindowPtr    createWindow( short rID, ResType rType='WIND', Boolean flot=false );
  50.         CWindowPtr    createWindow( Rect& r, xcmdString& title, short procID=palNoGrowProc, Boolean vis=true, Boolean flot=true );
  51.  
  52.         void        idleTime( long ticks=0 );
  53.  
  54.     public:    
  55.         // These are the default actions for the window. most do nothing.
  56.         //    client should override these with special features.
  57.         virtual    void        doOpenWindow( int show=true );    // Window is openning, initialize, show if hidden?
  58.         virtual    void        doCloseWindow( void );            // Window is closing, clean up
  59.         virtual    void        doShowHide( Boolean showFlag );    // Handle events relating to app4Evt.
  60.         virtual    void        doEditEvent( short what );        // Handle events relating to editing.
  61.  
  62.         virtual    void        doMenuUpdate( void );            // A menuBar click, set up menus
  63.         virtual    void        doMenuClick( long m, long i );    // A menu click
  64.         
  65.         virtual    void        doMessage( const xcmdString& msg );    // a send message to window...
  66.         
  67.         virtual    void        doSetProperty( const xcmdString& prop, const xcmdString& val );    // set a window property
  68.         virtual    xcmdString*    doGetProperty( const xcmdString& prop );    // get a window property (nil returned if invalid request)
  69.         virtual    void        doCursorWithin( void );                        // cursor is within the window */
  70.  
  71.         // These are the default actions for the standard event switches
  72.         //    notice that this list is not exhaustive.  If you wish to respond to other
  73.         //    events you need to supercede the doWindowEvent member above and handle the other
  74.         //    events.
  75.         virtual void        doIdleStuff( void );        // only gets called if idleTime > 0
  76.         virtual    void        doKeyDown( char keyChar, unsigned short modifiers=0 );
  77.         virtual    void        doMouseDown( short part );
  78.         virtual void        doActiveWindow( Boolean activating );    
  79.         virtual void        doUpdateWindow( void );    
  80.         virtual void        doDrawWindow( void );
  81.  
  82.     protected:
  83.         // These code wrappers are to be used with extreme caution as they require special
  84.         //    timing and consideration.  Make sure you understand how to use them and what
  85.         //    they mean.
  86.         void    allowReEntrancy( Boolean sysEvt, Boolean hcEvt );
  87.         void    hasInteruptCode( Boolean hasIcode );
  88.         void    alwaysMoveHigh( Boolean doIt );
  89.         void    close( void );
  90.         short    registerMenu( Boolean reg, short mResID );
  91.         // Use to register for text editing services.
  92.         void    beginEdit( void );
  93.         void    endEdit( void );
  94.  
  95.         // These functions must be used with great care.
  96.         // I don't check to see if the xEvent pointer is valid.
  97.         CWindowPtr        getXWindow( void );
  98.         void*            getXEventParam( int i );
  99.         void            setXEventResult( xcmdString* rv );
  100.         EventRecord*    getXEvent( void );
  101.         
  102.         Handle            getPrivateStorage( void )        { return xPrivStore; }
  103.         void            setPrivateStorage( Handle h )    { xPrivStore = h; }
  104.  
  105.         Boolean            isHidden( void )                { return !(((CWindowPeek)getXWindow())->visible); }
  106.         Boolean            isInBackground( void )            { return !(((CWindowPeek)getXWindow())->hilited); }
  107.     
  108.     private:
  109.         // For exposure only.  Private variables may change.
  110.         GrafPtr            oldXPort;        // copy of current port
  111.         XWEventInfoPtr    xEventInfo;        // the original XEvent ptr or nil if none.
  112.         Handle            xPrivStore;        // handle to "permanent" storage
  113.         CWindowPtr        xWindow;        // we are always a color window
  114.         EventRecord        xEvent;            // the event record
  115.  
  116.     };
  117.  
  118. #ifndef topLeft
  119. inline    Point*    topLeft(r)
  120.     {
  121.     return (((Point *) &(r))[0]) 
  122.     }
  123. #endif
  124.  
  125. #ifndef botRight
  126. inline    Point*    botRight(r)
  127.     {
  128.     return (((Point *) &(r))[1])
  129.     }
  130. #endif
  131.